package com.wish.g04.financing.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wish.g04.base.entity.CwCheckBatchDetail;
import com.wish.g04.base.service.ICwCheckBatchDetailService;
import com.wish.g04.common.core.utils.StringUtils;
import com.wish.g04.financing.dto.CheckBatchDetailDTO;
import com.wish.g04.financing.service.CheckBatchDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 对账批次明细表（保存对账结果明细的表） 服务实现类
 * </p>
 *
 * @author tyd
 * @since 2022-05-28
 */
@Service
public class CheckBatchDetailServiceImpl  implements CheckBatchDetailService {

    @Autowired
    private ICwCheckBatchDetailService  checkBatchDetailService;

    /**
     * 查询对账名次
     * @param checkBatchDetailDTO
     * @return
     */
    @Override
    public List<CwCheckBatchDetail> getBatchDetailList(CheckBatchDetailDTO checkBatchDetailDTO) {
        QueryWrapper<CwCheckBatchDetail> wrapper = new QueryWrapper<>();
        //渠道名称
        if (StringUtils.isNotEmpty(checkBatchDetailDTO.getTradeQudao())) {
            wrapper.eq("trade_qudao",checkBatchDetailDTO.getTradeQudao());
        }
        //交易结果
        if (null != checkBatchDetailDTO.getTradeResult()) {
            wrapper.eq("trade_result",checkBatchDetailDTO.getTradeResult());
        }
        //对账批次
        if (StringUtils.isNotEmpty(checkBatchDetailDTO.getBatchNo())) {
            wrapper.eq("batch_no",checkBatchDetailDTO.getBatchNo());
        }
        //交易金额
        if (StringUtils.isNotEmpty(checkBatchDetailDTO.getAmount())) {
            wrapper.eq("amount",checkBatchDetailDTO.getAmount());
        }
        //是否差错
        if (null != checkBatchDetailDTO.getHasDiff()) {
            wrapper.eq("has_diff",checkBatchDetailDTO.getHasDiff());
        }
        //差错处理
        if (null != checkBatchDetailDTO.getProcessState()) {
            wrapper.eq("process_state",checkBatchDetailDTO.getProcessState());
        }
        //支付方式
        if (null != checkBatchDetailDTO.getPayWay()) {
            wrapper.eq("pay_way",checkBatchDetailDTO.getPayWay());
        }
        List<CwCheckBatchDetail> checkBatchDetailList = checkBatchDetailService.list(wrapper);
        return checkBatchDetailList;
    }

    /**
     * 差错处理
     * @param checkBatchDetailDTO
     */
    @Override
    public boolean updateStatus(CheckBatchDetailDTO checkBatchDetailDTO) {
        UpdateWrapper<CwCheckBatchDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("has_diff",0);
        updateWrapper.set("process_state",checkBatchDetailDTO.getProcessState());
        updateWrapper.eq("id",checkBatchDetailDTO.getId());
         return  checkBatchDetailService.update(updateWrapper);
    }
}














